<template>
  <uni-nav-bar title="合伙人" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar color="#fff"
    backgroundColor="#558AF1" :border="false"></uni-nav-bar>
  <view class="package_sale" style="margin-top:0px;background:#558AF1;border-radius: 0px;color:#fff;" v-if="infor">
    <view>累计收益</view>
    <view style="font-size: 48rpx;margin:10rpx 0px;"><text style="font-size: 28rpx;">￥</text>{{infor.count}}</view>
    <view style="font-size: 24rpx;">本期收益：￥{{infor.month}}</view>
  </view>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <view class="package_sale space-between" v-for="(item,index) in attendanList" :key="item.id"
      @click="navTo('Sale/partner/partnerDetail?cart_code='+item.cart_code+'&cart_id='+item.id)"
      :style="{marginTop:index===0?'0px':'10rpx'}">
      <view class="center">
        <image :src="item.image" mode=""></image>
        <view class="direction-start">
          <text>{{item.cart_code}}</text>
          <text style="font-size:26rpx;color:#666;margin-top:10rpx;">入驻时间：{{item.createtime}}</text>
        </view>
      </view>
      <view>{{item.money}}</view>
    </view>
  </scroll-view>
</template>

<script setup lang="ts">
  import { navBack, navTo } from '@/utils/navigator';
  import { toPublish } from '@mqtt';
  import { ref } from 'vue';
  import { showLoading } from '@/utils/prompt';
  import { getPatnerMoney, getPatnerCart } from '@/gql/earthPushing/attendance';
  import { getDriverID } from '@/stores/driverID';
  const staff_id = getDriverID();
  const attendanList = ref([])
  const lastPage = ref(1);
  const currentPage = ref(1);
  const pageHeight = ref()
  const infor = ref()
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 175;
    },
  });
  partnerData()
  function partnerData() {
    showLoading()
    const payload = {
      query: getPatnerMoney,
      variables: {
        staff_id,
      },
    };
    toPublish(
      'ql/staff/getPatnerMoney',
      payload,
      (obj : any) => {
        const { getPatnerMoney } = obj.data;
        infor.value = getPatnerMoney
      }
    );
  }
  init()
  function init() {
    showLoading()
    const payload = {
      query: getPatnerCart,
      variables: {
        page: currentPage.value,
        staff_id,
      },
    };
    toPublish(
      'ql/staff/getPatnerCart',
      payload,
      (obj : any) => {
        const { getPatnerCart } = obj.data;
        attendanList.value = [...attendanList.value, ...getPatnerCart.list];
        lastPage.value = getPatnerCart.lastpage;
      }
    );
  }
  /**
   * 加载更多
   */
  function loadMore() {
    if (currentPage.value < lastPage.value) {
      currentPage.value++;
      init();
    }
  }
</script>

<style scoped lang="less">
  .center {
    image {
      width: 82rpx;
      height: 82rpx;
      background: #ECF0F6;
      border-radius: 8rpx;
      margin-right: 15rpx;
    }
  }
</style>